package com.xingdata.jjxc.favorites;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xingdata.jjxc.R;

/** 测试收藏夹做的一个测试版本adapter，当时数据加载不进去。其实是http的user_id被我写成了userid导致的*/
public class TestAdapter extends BaseAdapter {
	String TAG = "TestAdapter";
	private Context context;
	private List<FavoritesEntity> favoritesEntityList;
	private FavoritesEntity favoritesEntity;
	private LayoutInflater inflater;

	public TestAdapter(Activity favoritesActivity, List<FavoritesEntity> favoritesEntityList) {
		this.context = favoritesActivity;
		this.favoritesEntityList = favoritesEntityList;
	}

	@Override
	public int getCount() {
		return favoritesEntityList == null ? 0 : favoritesEntityList.size();
	}

	@Override
	public FavoritesEntity getItem(int position) {
		return favoritesEntityList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.favorites_listview_item, null);
			
			holder.place_name = (TextView) convertView.findViewById(R.id.place_name);
			
			holder.place_address = (TextView) convertView.findViewById(R.id.place_address);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.place_name.setText(favoritesEntityList.get(position).getPlace_name());
		Log.d(TAG, "testadpater+地名"+favoritesEntityList.get(position).getPlace_name());
		
		holder.place_address.setText(favoritesEntityList.get(position).getPlace_address());
		Log.d(TAG, "testadpater+地址"+favoritesEntityList.get(position).getPlace_address());
		return convertView;
	}

	final class ViewHolder {
		private TextView place_name;
		private TextView place_address;
	}
}
